#include <stdio.h>
#include <signal.h>

#include <ijpegd.h>
#include <cliijpegd.h>
#ifdef DMALLOC
#include <imp/dmalloc.h>
#endif

/* Ctrl-C handler */
static volatile int b_ctrl_c = 0;
static void sigint_handler(int a)
{
	b_ctrl_c = 1;
}

int main(int argc, char **argv)
{
	ijpegd_param_t param;
	cli_opt_t opt;
	int ret = 0;

	/* init ijpegd_param_t */
	if ((ret = init(argc, argv, &param, &opt)) < 0) {
		fprintf(stderr, "init failed\n");
		goto err_init;
	}

	/* Control-C handler */
	signal(SIGINT, sigint_handler);

	if ((ret = decode(&param, &opt, &b_ctrl_c)) < 0) {
		fprintf(stderr, "decode failed\n");
		goto err_decode;
	}

	/* deinit ijpegd_param_t */
	deinit(&param, &opt);

	return ret;

err_decode:
	deinit(&param, &opt);
err_init:
	return -1;
}
